package cn.pro.CCY.jdbc;

import java.sql.*;
import java.util.Scanner;

public class AppLogin {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入账号：");
        String username = scanner.nextLine();

        System.out.println("请输入密码：");
        String password = scanner.nextLine();

        login(username,password);
    }

    public static void login(String n,String p) throws Exception {
        System.out.println("username=" + n);
        System.out.println("password=" + p);
        String sql = "SELECT id FROM `user` WHERE username = '"
                + n + "' AND `password` = MD5('"+ p +"')";

        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:13306/test?useSSL=false";
        String user = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);
        if (set.next()) {
            System.out.println("登陆成功！");
        }else{
            System.out.println("登陆失败！");


        }

    }
}
